package com.cloud.tsp.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.cloud.api.constants.StrVo;
import com.cloud.api.domain.forward.Platform;
import com.cloud.api.domain.forward.QueryPlatform;
import com.cloud.api.domain.forward.UpdateStatus;
import com.cloud.core.util.R;
import com.cloud.log.annotation.Log;
import com.cloud.log.enums.BusinessType;
import com.cloud.log.enums.OperatorType;
import com.cloud.mybatis.domain.TableDataInfo;
import com.cloud.tsp.service.IPlatformService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author haohaibo
 * @since 2024-01-08
 */
@RestController
@RequestMapping("/platform")
public class PlatformController {

    @Resource
    private IPlatformService platformService;


    @Tag(name = "v1.0")
    @Operation(summary = "转发平台管理分页（管理）")
    @PostMapping("/getPlatformList")
    @Log(title = "平台管理-转发平台管理分页", businessType = BusinessType.OTHER, operatorType = OperatorType.MANAGE)
    public TableDataInfo<Platform> selectPlatformList(@RequestBody @Valid QueryPlatform para){
        return platformService.selectPlatformList(para);
    }

    @Tag(name = "v1.0")
    @Operation(summary = "转发平台全部（管理）")
    @PostMapping("/getAllPlatformList")
    @Log(title = "平台管理-转发平台全部", businessType = BusinessType.OTHER, operatorType = OperatorType.MANAGE)
    public R<Platform> selectAllPlatformList(){
        LambdaQueryWrapper<Platform> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(Platform::getId,Platform::getPlatformName);
        List<Platform> list = platformService.list(queryWrapper);
        return R.ok(list);
    }


    @Tag(name = "v1.0")
    @Operation(summary = "新增或修改平台（管理）")
    @PostMapping("/InsertOrUpdate")
    @Log(title = "平台管理-新增或修改平台", businessType = BusinessType.OTHER, operatorType = OperatorType.MANAGE)
    public R InsertOrUpdate(@RequestBody @Valid Platform para){
        platformService.InsertOrUpdate(para);
        return R.ok();
    }

    @Tag(name = "v1.0")
    @Operation(summary = "删除平台（管理）")
    @PostMapping("/deletedById")
    @Log(title = "平台管理-删除平台", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    public R deletedById(@RequestBody @Valid StrVo para){
        platformService.deletedById(para.getId());
        return R.ok();
    }

    @Tag(name = "v1.0")
    @Operation(summary = "连接与断开（管理）")
    @PostMapping("/updateStatus")
    @Log(title = "平台管理-连接与断开", businessType = BusinessType.UPDATE, operatorType = OperatorType.MANAGE)
    public R updateStatus(@RequestBody @Valid UpdateStatus para){
        platformService.updateStatus(para);
        return R.ok();
    }

}